﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OSA.Policlinic.BusinessApplication.Registry;
using Policlinica;
using NLog;

namespace OSA.Policlinic.UI.WFApplication
{
    public partial class chooseDoctorForm : Form
    {
        private IRegistryBusinessApplication registryBusinessApplication;
        private List<Doctor> doctors;
        public Doctor ChoosedDoctor;
        private static Logger logger = LogManager.GetCurrentClassLogger();

        public chooseDoctorForm()
        {
            InitializeComponent();
            registryBusinessApplication = RegistryBusinessApplicationHome.GetInstanse();
            doctors = registryBusinessApplication.GetAllDoctors();
            doctorBindingSource.DataSource = doctors;
            logger.Trace("Форма chooseDoctorForm успешно инициализирована");
        }

        private void doctorDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                ChoosedDoctor = (Doctor)doctorDataGridView.Rows[e.RowIndex].DataBoundItem;
                if (ChoosedDoctor != null)
                {
                    logger.Debug("Для выдачи талона выбран доктор id = {0}", ChoosedDoctor.Id);
                    this.Close();
                }
            }
        }

        private void SearchBySpecializationButton_Click(object sender, EventArgs e)
        {
            doctors = registryBusinessApplication.GetDoctorsBySpecialisation(SpecializationTextBox.Text);
            doctorBindingSource.DataSource = doctors;
            logger.Debug("Произведен поиск врачей специализации {0}", SpecializationTextBox.Text);
        }

        private void ClearButton_Click(object sender, EventArgs e)
        {
            doctors = registryBusinessApplication.GetAllDoctors();
            doctorBindingSource.DataSource = doctors;
        }

    }
}
